package com.heima.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbSkuClassMapper;
import com.heima.pojo.TbSkuClass;
import com.heima.pojo.vo.PageResponse;
import com.heima.service.ITbSkuClassService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品类别表 服务实现类
 * </p>
 *
 * @author nan
 * @since 2024-06-04
 */
@Service
public class TbSkuClassServiceImpl extends ServiceImpl<TbSkuClassMapper, TbSkuClass> implements ITbSkuClassService {

    @Override
    public PageResponse<TbSkuClass> getByPage(Integer pageIndex, Integer pageSize, String className) {
        LambdaQueryWrapper<TbSkuClass> wrapper = new LambdaQueryWrapper<>();
        if(ObjectUtil.isNotEmpty(className)){
            wrapper.like(TbSkuClass::getClassName,className);
        }
        Page<TbSkuClass> page = page(new Page<>(pageIndex, pageSize), wrapper);

        PageResponse<TbSkuClass> pageSkuClassVo = new PageResponse<>();
        pageSkuClassVo.setPageIndex(page.getCurrent());
        pageSkuClassVo.setPageSize(page.getSize());
        pageSkuClassVo.setTotalPage(page.getTotal());
        pageSkuClassVo.setTotalCount(page.getSize());
        pageSkuClassVo.setCurrentPageRecords(page.getRecords());
        return pageSkuClassVo;
    }
}
